home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 August / Chip_1999-08_cd.bin / zkuste / MacOS / Files / His.sit / Hi's Universal Saver v.1.6.0 ∫ / Parts to Install / Menu Events 1.3.1 / Menu Events Help (text) < prev    next >
Text File  |  1998-01-07  |  44KB  |  986 lines

  1. Menu Events 1.3.1
  2.  
  3. December 13, 1997
  4.  
  5.  
  6.  
  7. Disclaimer and Copyright Notice
  8.  
  9.  
  10. Menu Events is a free utility which lets you control another application╒s
  11. menu commands by sending it an Apple event.  The author, Ross Brown,
  12. makes no warranty, either express or implied, with respect to this
  13. software, its performance, merchantability, or suitability for any
  14. particular purpose.  People using the Menu Events utility do so at their
  15. own risk.  The author disclaims all liability for loss of data, mechanical
  16. damage, or other losses suffered while using the Menu Events utility.
  17.  
  18. Menu Events is an AWOL Software Production, Copyright ⌐ 1994-7 Ross
  19. Brown.  All rights reserved.  Permission is granted to make and distribute
  20. copies of this software, provided this disclaimer and copyright notice are
  21. preserved on all copies.  The software may not, however, be sold or
  22. distributed for profit, or included with other software which is sold or
  23. distributed for profit, without the permission of the author.
  24.  
  25. There are no site license fees for the use of Menu Events within an
  26. organization.  The author encourages you to make and distribute as many
  27. copies of the system extension as you wish, for whomever you wish, as
  28. long as it is not for profit.  Menu Events is part of a set of cooperating
  29. programs, AWOL Utilities.  The tutorial help you are reading is designed
  30. for handling by the help server application Help on Wheels, which is also
  31. part of AWOL Utilities.
  32.  
  33.  
  34.  
  35. Distribution Policy
  36.  
  37.  
  38. New versions of individual AWOL Utilities programs, including Menu
  39. Events, are available by anonymous FTP from popular archive sites
  40. including <ftp://sumex-aim.stanford.edu/info-mac/> and its various
  41. mirror sites, such as <ftp://mirrors.aol.com/pub/info-mac/>.
  42.  
  43. For the latest information about AWOL software, including AWOL Utilities,
  44. please visit the AWOL Web page at <http://www.magma.ca/~awolsp/>.
  45.  
  46. Support for AWOL Utilities is through Internet mail at
  47. <mailto:ab026@freenet.carleton.ca>.  The software is not available by
  48. FTP from this site.  The address for paper correspondence is AWOL
  49. Software Productions, PO Box 24207, Hazeldean RPO, Kanata, Ontario,
  50. Canada K2M 2C3.
  51.  
  52. Macintosh users who do not have access to electronic sources of free and
  53. shareware software may obtain a copy of AWOL Utilities by sending a
  54. self-addressed stamped envelope and an 800K (or larger) formatted
  55. diskette to the author at the above address.  U.S. users are reminded that
  56. postage from Canada in 1997 is C$0.52 up to 30 grams (1 oz.), C$0.77 up
  57. to 50 grams (1 3/4 oz.), and C$1.17 up to 100 grams (3 1/2 oz.).
  58. US$0.50, US$0.75, and US$1.00 in coin is acceptable in place of stamps
  59. for the respective weights.  People outside the U.S. and Canada may send
  60. an international postal reply coupon instead of Canadian stamps (available
  61. from any post office).  Please use sturdy envelopes, preferably cardboard
  62. disk mailers.  (Mailers over 5 mm (1/5") thick require C$1.17 postage to
  63. the U.S.)
  64. Please do not send return envelopes with non-Canadian
  65. stamps, as Canada Post will not accept them.
  66.  
  67.  
  68.  
  69. About AWOL Software Productions
  70.  
  71.  
  72. AWOL Software Productions specializes in custom development of
  73. software for the Mac OS.  Since its inception in 1990, AWOL has
  74. developed a number of programs which enhance the Mac OS user
  75. experience, working in nearly every part of the Macintosh Toolbox.  If
  76. you have a short-term programming task or product idea but lack the
  77. staff to do the expert design, coding, and documentation, we invite your
  78. inquiry.
  79.  
  80. Virtual Desktop is AWOL╒s best-known effort, serving the desktop
  81. expansion needs of thousands of Mac users around the world.  Later in
  82. 1997, AWOL will release a new commercial version 2.0 to replace the
  83. freeware version contained in the AWOL Utilities package.  Please contact
  84. us at <mailto:ab026@freenet.carleton.ca> for feature and ordering
  85. information.
  86.  
  87. Users who want more out of the Mac╒s speech capabilities should check
  88. out MacYack Pro, a jointly developed package of speech tools marketed by
  89. Scantron Quality Computers (<http://www.lowtek.com/macyack/>;
  90. <mailto:qualitycomp@aol.com>; 20200 Nine Mile Rd., St. Clair Shores, MI
  91. 48080).
  92.  
  93.  
  94.  
  95. Purpose
  96.  
  97.  
  98. The big trend these days in Macintosh software is toward more
  99. integration between applications.  Increasingly, developers achieve this
  100. integration by using the Apple event interfaces of other applications, and
  101. by defining their own suites of Apple events for other applications to use.
  102.  
  103. Because there are far more clients than servers in the world of Apple
  104. events, there is a large number of ╥high-level-event-aware╙ applications
  105. which support program linking, using Apple events to control other
  106. applications (or just to be modern), but not offering any interface of their
  107. own.  Apart from the Required suite mandated by Finder, the functionality
  108. of these applications is beyond the reach of scripting utilities and other
  109. programs that send Apple events.  Menu Events is a utility which opens up
  110. this demi-monde of dabblers and dilettantes to the glories of Apple event
  111. controllability.  Applications which are by their nature only
  112. high-level-event-aware become scriptable and recordable Apple event
  113. servers.
  114.  
  115. If you regard an application╒s collective user interface in terms of a set
  116. of available functions, then take subsets according to how the user can
  117. access these functions (Command-key combination, button click, menus,
  118. and so on), you will usually find that the subset for menus is largest.  This
  119. is because menus are intended as a baseline for the user interface;
  120. however else you can do something, you should be able to do it with menus
  121. as well.  Often a function is not available in a certain mode, but a menu
  122. selection will shift the application into that mode, then another will access
  123. the function.  This conformity is an asset of the Macintosh operating
  124. system which can be exploited to offer a fairly general means of
  125. controlling other applications.
  126.  
  127.  
  128.  
  129. Who Can Use Menu Events?
  130.  
  131.  
  132. You do not need AppleScript, or any other optional software package, for
  133. Menu Events to work.  It only requires System 7.
  134.  
  135. However, it has no user interface of its own.  It only enables programs to
  136. do something they would not otherwise be able to do, namely, invoke
  137. another application╒s menu commands.
  138.  
  139. Any program you write, or any application which lets you compose and
  140. send Apple events (such as a general scripting utility, or Maybe, part of
  141. AWOL Utilities), can send a Menu event to any suitably modern application
  142. and hope for a response.  Whether or not a particular application
  143. cooperates depends on how it was programmed, but any application
  144. programmed according to the published instructions of Apple Computer
  145. will cooperate, with a bit of coaxing.
  146. See the section entitled ╥Limitations╙ for more information.
  147.  
  148. Menu events can be received from any machine on the AppleTalk network,
  149. subject to the usual Users & Groups program linking permission scheme.
  150. This allows you to use Menu events to control applications from a remote
  151. location.
  152.  
  153. If you have AppleScript, you should place the ╥Menu Events Scripting
  154. Addition╙ file in your ╥Scripting Additions╙ folder.  This will allow you
  155. to use Menu events in your scripts.  (Unlike most scripting additions, this
  156. one only describes event terminology, and does not implement the event
  157. handlers themselves, so it is useless without the Menu Events extension.)
  158. ╥Menu Events Sample Script╙ shows the sort of thing you can do with the
  159. scripting addition file installed.  Before writing a script to control a
  160. target application, you should try recording its menu actions using your
  161. script editor.  If the target application supports program linking, and the
  162. Caps Lock key is down, these actions will be recorded as Menu Events
  163. script commands.
  164.  
  165.  
  166.  
  167. What Does Menu Events Do?
  168.  
  169.  
  170. Menu Events is a system extension.  Once you have placed it in your
  171. Extensions folder and restarted your Macintosh, it adds a small suite of
  172. Apple events (╥Menu events╙) to the set supported by every
  173. high-level-event-aware application.  Also, if the Caps Lock key is down,
  174. it alters menu selection logic so that the selection is recorded as a Menu
  175. event.  This capability allows a script editor to record menu actions as
  176. script commands.
  177.  
  178. Many people are justly wary of control panels and system extensions,
  179. because of the conflicts they often cause with System software and with
  180. each other.  These conflicts usually result from competitive trap patching.
  181.  
  182. Menu Events installs a GetNextEvent filter and patches the MenuSelect
  183. trap at system startup to enable the Apple event recording capability, and
  184. installs an Apple event handler in the system dispatch table.  The Apple
  185. event handler cannot conflict with any other, because it is bound
  186. specifically to the Menu event class.  Menu Events does patch some traps
  187. ╥on the fly╙ to simulate menu selection, but the patches remove
  188. themselves immediately.
  189.  
  190. There are three events defined in the suite, and they work as follows.
  191. See the section entitled ╥Menu Events Suite╙ for more information on the
  192. Menu Events suite.
  193.  
  194.  
  195. Query Menu List Event
  196.  
  197. This event, with no parameters, queries the menu list of the target
  198. application.  If the application is high-level-event-aware, not
  199. background-only, and has a menu bar, it will return a list of records, each
  200. containing a menu ID (integer), a title (string), an enable/disable
  201. (Boolean), and a menu definition procedure resource ID (integer)
  202. parameter.  If you do not know the IDs or titles of the target application╒s
  203. menus, this is one way to find out.  (Another way is to press the Caps
  204. Lock key and record menu actions using a script editor; yet another is to
  205. use the Menu Grabber application, also part of AWOL Utilities.)  Be aware
  206. that menu IDs do not have to agree with 'MENU' resource IDs, though they
  207. often do.
  208. See the section entitled ╥Suggestions for Use╙ for more information on
  209. Menu Grabber.
  210.  
  211. System menus (Keyboard, Help, Application), hierarchical menus, and
  212. pop-up menus do not appear in this list, but the Apple menu does.
  213.  
  214. NOTE:  The standard menu definition procedure ('MDEF') resource ID is 0.
  215. A value of -1 indicates that the menu definition procedure is not a
  216. resource.  Non-standard menu definition procedures may have abnormal
  217. ways of counting, disabling, and displaying menu items, so be careful with
  218. them.
  219.  
  220.  
  221. Query Menu Event
  222.  
  223. This event, given a menu ID (integer) and/or menu title (string)
  224. parameter, queries the items of a certain target application menu.  If the
  225. application has a menu with that ID and/or title, be it a regular, system,
  226. hierarchical, or pop-up menu, it will return a list of records, one per
  227. menu item, each containing a menu item ID (integer), an item text
  228. (string), an enable/disable (Boolean), a mark character (integer), an icon
  229. ID (integer), a style value (integer), and a Command character (integer)
  230. parameter.  The items are numbered starting from 1 at the top end of the
  231. menu.  Separators appear as disabled items with an item text of ╥-╙.
  232.  
  233. This event simulates a simple click in the application╒s menu bar, to force
  234. it to bring its menus up to date.
  235.  
  236. You may optionally include Boolean parameters to indicate which modifier
  237. keys (Shift, Control, Option, Command) are pressed at the time of the
  238. simulated menu bar click, in case this makes a difference in the content of
  239. the menu.
  240.  
  241. This event does work for menus which use a non-standard menu definition
  242. procedure ('MDEF'), but the results may or may not reflect what you see
  243. when you pull down the menu, depending on how the procedure was
  244. programmed.
  245.  
  246. This event brings the target application to the front before forcing the
  247. menu bar click upon it.  If the sender was on the same machine, and was
  248. previously in front, it returns to the front after the menu query is
  249. complete.
  250. See the section entitled ╥How Does Menu Events Work?╙ for more
  251. information about the method by which Menu Events activates the target
  252. application.
  253.  
  254.  
  255. Select Menu Item Event
  256.  
  257. This event, given a menu ID (integer) and/or menu title (string)
  258. parameter and a menu item ID (integer) and/or menu item text (string)
  259. parameter, asks the application to act as though the user pulled down that
  260. menu and selected that item.  This does not work for the Keyboard and
  261. Application menus, which are not under the control of the application, nor
  262. for the upper (System-defined) part of the Help menu, but it works for
  263. any regular, application-defined, enabled menu item.
  264.  
  265. If you use the menu item text parameter to specify the menu item to
  266. select, be sure to match any special characters in the text, especially the
  267. ellipsis ('╔') character which often appears at the end of the string,
  268. which is not the same as three period characters, despite its appearance.
  269.  
  270. You may optionally include Boolean parameters to indicate which modifier
  271. keys (Shift, Control, Option, Command) are pressed at the time of the
  272. simulated menu item selection, in case this makes a difference in the
  273. effect of the selection.
  274.  
  275. This event does work for menus which use a non-standard menu definition
  276. procedure ('MDEF'), but the results may or may not reflect what happens
  277. when you select from the menu, depending on how the procedure was
  278. programmed.
  279.  
  280. This event brings the target application to the front before forcing the
  281. menu selection upon it.  If the sender was on the same machine, and was
  282. previously in front, it returns to the front after the menu action is
  283. complete.
  284. See the section entitled ╥How Does Menu Events Work?╙ for more
  285. information about the method by which Menu Events activates the target
  286. application.
  287.  
  288.  
  289.  
  290. How Does Menu Events Work?
  291.  
  292.  
  293. When you send a Query Menu List event, the ideal application dispatches
  294. the resulting high-level event as an Apple event without looking at it.  The
  295. event handler provided by Menu Events forms a reply to the query on the
  296. basis of the application╒s menu list structure.  Through all of this, the
  297. application stays in the background or in the foreground, wherever it was
  298. before.
  299.  
  300. When you send a Query Menu or Select Menu Item event, the same things
  301. happen, but the event handling is more complex.
  302.  
  303. First, it verifies that the given menu is valid.  If not, it returns
  304. noSuchMenuErr.
  305.  
  306. Second, it asks for the application to be brought to the front for user
  307. interaction, because it could be dangerous to feed the target application a
  308. menu bar click while it is in the background, something that never happens
  309. in normal operation.  If it is refused, it returns errAENoUserInteraction.
  310.  
  311. Third, it patches some traps so that it can gain control of menu bar clicks.
  312. If it finds that the patches are already in place, meaning that an earlier
  313. Menu event is still pending, it returns menuEventPendingErr.
  314.  
  315. Fourth, if everything is OK, it posts an event to simulate a mouse click in
  316. the menu bar, with modifier keys if specified.  The patched traps tell the
  317. application that no menu item was selected.  The patches then remove
  318. themselves.  This step is solely to ensure that the application brings its
  319. menus up to date.
  320.  
  321. Fifth (in the case of a Select Menu Item event), it verifies that the given
  322. menu item is valid and enabled.  If not, it returns noSuchMenuErr,
  323. noSuchMenuItemErr, or menuItemDisabledErr.  If the menu has a
  324. non-standard menu definition procedure, its way of counting or disabling
  325. items may differ from the norm.  Menu Events assumes that the count and
  326. enable/disable flags are set in the normal fashion.
  327.  
  328. Sixth (in the case of a Select Menu Item event), it posts an event to
  329. simulate another mouse click in the menu bar, with modifier keys if
  330. specified.  The patched traps tell the application that the given item was
  331. selected.  The patches then remove themselves.  From there, it is exactly
  332. as though the user had actually made the selection.
  333.  
  334. NOTE:  When replying to any of the three event types, Menu Events
  335. includes a null ╥tattoo╙ parameter to prove that it handled the event,
  336. rather than some handler supplied by the application.  Many Microsoft
  337. applications, for example, bind their own handler over all Apple event
  338. classes, preventing Menu Events from working.  (The handler wouldn╒t be
  339. a problem if it returned errAEEventNotHandled when faced with an
  340. unknown Apple event, as it should.)
  341.  
  342.  
  343. User Interaction Policy
  344.  
  345. The Apple Event Manager implements a complicated but sensible model for
  346. joint sender/receiver control over user interaction.  Menu Events doesn╒t
  347. know which menu selections will really require user interaction, but even
  348. if it did, it would still have to request user interaction just to bring the
  349. target application to the front, where an application always expects to be
  350. when it sees a mouse-down event.
  351.  
  352. The sending program must set the kAECanInteract or kAEAlwaysInteract
  353. flag in the sendMode parameter to AESend, in order to achieve user
  354. interaction.  It should also set the kAECanSwitchLayer flag, allowing the
  355. target application to come to the front without having to post a
  356. notification request.  If the target application is in the background, and
  357. receives a Menu event with this flag not set, it may go into a notification
  358. wait state, disrupting its usual background event processing behavior.
  359.  
  360. If both the sending program and target application are in the background,
  361. the kAECanSwitchLayer flag has no effect, and the notification request is
  362. posted anyway.  Since your sending program is indirectly instigating a
  363. user interaction, it should call AEInteractWithUser before sending the
  364. Menu event, if there is any chance that it will be in the background at the
  365. time.  Another approach would be to call SetFrontProcess to activate the
  366. target application before sending it a Menu event.
  367.  
  368. If the target application is in that rare user interaction state,
  369. kAEInteractWithSelf, where it disallows interaction requested by any
  370. other process, the Menu event handler will respect that state, and refuse
  371. the event.
  372.  
  373. If the sending and receiving applications are on different machines, the
  374. usual program linking checks apply, namely, Sharing Setup (on/off),
  375. Users & Groups (permission to user), and Finder╒s Sharing (permission to
  376. application).
  377.  
  378. If the Menu Events extension is locked, using Finder╒s Get Info dialog, then
  379. only target applications which explicitly allow interaction with all
  380. processes can be controlled by remote senders.  If it is not locked, and if
  381. it sees that the user interaction state is kAEInteractWithLocal, which is
  382. the default value, it will momentarily change it to kAEInteractWithAll, so
  383. that events sent from a remote machine are not rejected.  This trick is
  384. necessary for Menu Events to be useful with most target applications,
  385. because most will assume the default interaction state, not expecting any
  386. remote sender to require user interaction.  The icon displayed by Menu
  387. Events at startup shows whether or not the lock is in effect.
  388.  
  389. IMPORTANT NOTE:  Users of machines where Menu Events is installed
  390. should be careful about which users and applications are enabled for
  391. remote program linking.  In particular, guest users should not be allowed
  392. to do program linking unless Menu Events is locked.
  393.  
  394.  
  395. Apple Event Recording Capability
  396.  
  397. When you are using a high-level-event-aware application on a machine
  398. where Menu Events is installed, menu item selection behavior is modified
  399. if the Caps Lock key is down at the time you release the mouse button.
  400. Menu Events will create a Select Menu Item Apple event to represent the
  401. selection (including parameters for any modifier keys which were
  402. pressed), so that a script editor can record the event as a script
  403. command.  A gentle ╥twang╙ sound confirms that this has happened.
  404. Whether or not it succeeds in recording the event, the menu selection will
  405. be processed in the usual way.
  406.  
  407. If the application is scriptable in its own right, a script editor may record
  408. two commands when you select an item from its menus.  To prevent this
  409. duplication, you can use the item╒s Command-key equivalent (if any), or
  410. release the Caps Lock key, to suppress the recording capability.
  411.  
  412. If an application seems to be misinterpreting or not receiving menu
  413. selections, try again with the Caps Lock key up.  The command will not be
  414. recorded, but should work as usual.
  415.  
  416. NOTE:  While receiving a Select Menu Item event does simulate a menu
  417. selection, it does not cause a Select Menu Item script command to be
  418. recorded.
  419.  
  420.  
  421.  
  422. Suggestions for Use
  423.  
  424.  
  425. Menu Events is distributed as part of a free set of cooperating programs,
  426. AWOL Utilities.  This section explains how Menu Events can work in
  427. conjunction with the other programs.
  428.  
  429.  
  430. Help on Wheels
  431.  
  432. Help on Wheels is an efficient and full-featured help server which displays
  433. help files on behalf of client applications.  The help file you are reading is
  434. distributed alongside the Menu Events extension file as a separate Help on
  435. Wheels document.
  436.  
  437. Because Menu Events is not an application, its help support is limited.  To
  438. read this help, press the Help or Command-? key while the machine is
  439. starting up, and release the key once you see the Menu Events icon with a
  440. help balloon on it.  The help server will open to display the help file after
  441. startup is complete.
  442.  
  443.  
  444. Maybe
  445.  
  446. Maybe, the Finder alias enhancer, has an option allowing you to script a
  447. single Apple event and choose its target.  This Apple event will be sent
  448. just before the alias target is opened or printed.  In this way, you can
  449. achieve the effect of sending a simple Menu event by opening the
  450. converted alias.
  451.  
  452. Maybe does not require AppleScript or any other scripting system to send
  453. a Menu event.  Many programs, including all kinds of scripting utilities,
  454. offer a similar opportunity to send Menu events to any target application
  455. you choose.
  456.  
  457.  
  458. Menu Grabber
  459.  
  460. AWOL Utilities also contains an application, Menu Grabber, which uses
  461. Menu events to swap any target application╒s menu bar over its own.
  462. This allows you to command most of the application╒s functions from a
  463. remote location, although you will not see anything but the menus.  For
  464. most target applications, Menu Grabber will only be able to select menu
  465. items from a remote machine if the target╒s copy of Menu Events was
  466. unlocked at startup.
  467. See the section entitled ╥User Interaction Policy╙ for more information
  468. about the effect of locking the Menu Events extension.
  469.  
  470. When Menu Grabber grabs a menu, it adds a disabled item to show the
  471. menu ID.  This may help you if you are writing a program or script to send
  472. a Menu event to the application.
  473.  
  474.  
  475.  
  476. Menu Events Suite
  477.  
  478.  
  479. The following is a formal description of the Menu Events suite, in the form
  480. used in the Apple Event Registry.
  481.  
  482. NOTE:  The C header file ╥Menu Events.h╙╩contains the constant
  483. definitions which appear here.  The ╥Menu Events Scripting Addition╙ file
  484. contains an 'aete' resource which records the following dictionary
  485. information, for the benefit of scripting packages such as AppleScript.
  486. This package also includes a sample script, ╥Menu Events Sample
  487. Script,╙ which demonstrates the usage of the following events and
  488. parameters.
  489.  
  490.  
  491. Apple events defined in the Menu Events suite
  492.  
  493. Name              Requested action
  494.  
  495. Query Menu List   List all application-defined menus
  496. Query Menu        List all items in a menu
  497. Select Menu Item  Perform a menu command
  498.  
  499.  
  500. Query Menu List - list all application-defined menus
  501.  
  502. A Query Menu List Apple event asks the application to return a list of
  503. records containing information about all menus defined by the application
  504. in its menu bar.  This information includes the Apple menu, but not the
  505. Help, Keyboard, or Application menus.
  506.  
  507. Event Class       kMEEventClass
  508.  
  509. Event ID          kAEMEQueryMenuList
  510.  
  511. Parameters        none
  512.  
  513. Reply Parameters
  514.  
  515. keyDirectObject
  516.                   Description:  A list of Apple event
  517.                                 records, one for each
  518.                                 menu, each containing the
  519.                                 following parameters
  520.                   Descriptor Type:  typeAEList
  521.                   Required or Optional?  Required
  522.  
  523.    keyMenuID
  524.                   Description:  The ID of the menu, not
  525.                                 necessarily equal to the
  526.                                 ID of the 'MENU' resource
  527.                                 it may have come from
  528.                   Descriptor Type:  typeShortInteger
  529.                   Required or Optional?  Required
  530.    keyMenuTitle
  531.                   Description:  The title of the menu, as
  532.                                 it appears in the menu bar
  533.                   Descriptor Type:  typeChar
  534.                   Required or Optional?  Required
  535.    keyMenuEnabled
  536.                   Description:  Whether or not the menu, as
  537.                                 a whole, is enabled
  538.                   Descriptor Type:  typeBoolean
  539.                   Required or Optional?  Required
  540.    keyMenuMDEFID
  541.                   Description:  The ID of the menu definition
  542.                                 procedure ('MDEF') resource,
  543.                                 ordinarily 0; -1 signifies
  544.                                 that the definition procedure
  545.                                 is not a resource
  546.                   Descriptor Type:  typeShortInteger
  547.                   Required or Optional?  Required
  548.  
  549. keyMenuEventsTattoo
  550.                   Description:  A null parameter to verify
  551.                                 that Menu Events handled
  552.                                 the event
  553.                   Descriptor Type:  typeNull
  554.                   Required or Optional?  Required
  555.  
  556. Result Codes
  557.                   mBarNFnd        -126    The application has
  558.                                           no menu bar
  559.  
  560.  
  561. Query Menu - list all items in a menu
  562.  
  563. A Query Menu Apple event asks the application to return a list of records
  564. containing information about all items in a given menu (selected by ID
  565. and/or title).  It requests user interaction to bring the application to the
  566. front, then posts mouse events to simulate a click in the menu bar, with
  567. modifier key states as specified, to force the application to update its
  568. menus, then reads the items from the given menu.  This information is
  569. complete enough to reconstruct the menu, except for the icon resources
  570. referenced by the keyMenuItemIcon parameter.
  571.  
  572. Event Class       kMEEventClass
  573.  
  574. Event ID          kAEMEQueryMenu
  575.  
  576. Parameters
  577.  
  578. keyMenuID
  579.                   Description:  The ID of the menu, as
  580.                                 returned by a Query Menu
  581.                                 List Apple event
  582.                   Descriptor Type:  typeShortInteger
  583.                   Required or Optional?  Optional
  584. keyMenuTitle
  585.                   Description:  The title of the menu, as
  586.                                 returned by a Query Menu
  587.                                 List Apple event
  588.                   Descriptor Type:  typeChar
  589.                   Required or Optional?  Optional
  590. NOTE:  Either keyMenuID or keyMenuTitle, or both, must be specified.
  591. keyShiftKeyPressed
  592.                   Description:  Whether the Shift key is
  593.                                 pressed at the time of the
  594.                                 simulated menu bar click
  595.                   Descriptor Type:  typeBoolean
  596.                   Required or Optional?  Optional
  597.                   Default Value:  false
  598. keyControlKeyPressed
  599.                   Description:  Whether the Control key is
  600.                                 pressed at the time of the
  601.                                 simulated menu bar click
  602.                   Descriptor Type:  typeBoolean
  603.                   Required or Optional?  Optional
  604.                   Default Value:  false
  605. keyOptionKeyPressed
  606.                   Description:  Whether the Option key is
  607.                                 pressed at the time of the
  608.                                 simulated menu bar click
  609.                   Descriptor Type:  typeBoolean
  610.                   Required or Optional?  Optional
  611.                   Default Value:  false
  612. keyCommandKeyPressed
  613.                   Description:  Whether the Command key is
  614.                                 pressed at the time of the
  615.                                 simulated menu bar click
  616.                   Descriptor Type:  typeBoolean
  617.                   Required or Optional?  Optional
  618.                   Default Value:  false
  619.  
  620. Reply Parameters
  621.  
  622. keyDirectObject
  623.                   Description:  A list of Apple event
  624.                                 records, one for each
  625.                                 item, each containing the
  626.                                 following parameters
  627.                   Descriptor Type:  typeAEList
  628.                   Required or Optional?  Required
  629.  
  630.    keyMenuItemID
  631.                   Description:  The ID of the item, numbered
  632.                                 from 1 at the top of the menu
  633.                   Descriptor Type:  typeShortInteger
  634.                   Required or Optional?  Required
  635.    keyMenuItemText
  636.                   Description:  The text of the item, as
  637.                                 it appears in the menu
  638.                   Descriptor Type:  typeChar
  639.                   Required or Optional?  Required
  640.    keyMenuItemEnabled
  641.                   Description:  Whether or not the item is
  642.                                 enabled
  643.                   Descriptor Type:  typeBoolean
  644.                   Required or Optional?  Required
  645.    keyMenuItemMark
  646.                   Description:  The mark character of the
  647.                                 item, in the lower byte
  648.                   Descriptor Type:  typeShortInteger
  649.                   Required or Optional?  Required
  650.    keyMenuItemIcon
  651.                   Description:  The icon number of the item,
  652.                                 which is 256 less than the
  653.                                 resource ID of the 'ICON' or
  654.                                 'cicn' resource
  655.                   Descriptor Type:  typeShortInteger
  656.                   Required or Optional?  Required
  657.    keyMenuItemStyle
  658.                   Description:  The style value of the item,
  659.                                 in the lower byte
  660.                   Descriptor Type:  typeShortInteger
  661.                   Required or Optional?  Required
  662.    keyMenuItemCmd
  663.                   Description:  The Command-key equivalent
  664.                                 character of the item, in the
  665.                                 lower byte
  666.                   Descriptor Type:  typeShortInteger
  667.                   Required or Optional?  Required
  668.  
  669. keyMenuEventsTattoo
  670.                   Description:  A null parameter to verify
  671.                                 that Menu Events handled
  672.                                 the event
  673.                   Descriptor Type:  typeNull
  674.                   Required or Optional?  Required
  675.  
  676. Result Codes
  677.                   mBarNFnd        -126    The application has
  678.                                           no menu bar
  679.                   errAENoUserInteraction
  680.                                   -1713   The application is
  681.                                           refusing to interact
  682.                                           with other processes
  683.                                           or (if Menu Events
  684.                                           extension is locked)
  685.                                           with remote processes
  686.                   noSuchMenuErr   -15950  The application has
  687.                                           no such menu
  688.                   menuMismatchErr
  689.                                   -15955  The given menu ID
  690.                                           and menu title
  691.                                           do not match
  692.  
  693.  
  694. Select Menu Item - perform a menu command
  695.  
  696. A Select Menu Item event simulates the selection of a command (selected
  697. by item ID and/or item text) from a menu (selected by ID and/or title).  It
  698. requests user interaction to bring the application to the front, then posts
  699. mouse events to simulate the selection of the given menu item, with
  700. modifier key states as specified.  If the Menu event is correctly handled,
  701. and the application reacts to the mouse events in the usual way, the result
  702. is as if the user had actually selected that menu item.  Interaction will fail
  703. if the application refuses to interact with other processes
  704. (kAEInteractWithSelf mode), or, if the application is on another machine
  705. and the Menu Events extension has been locked, if it refuses to interact
  706. with remote processes (kAEInteractWithLocal mode).
  707.  
  708. Event Class       kMEEventClass
  709.  
  710. Event ID          kAEMESelectMenuItem
  711.  
  712. Parameters
  713.  
  714. keyMenuID
  715.                   Description:  The ID of the menu, as
  716.                                 returned by a Query Menu
  717.                                 List Apple event
  718.                   Descriptor Type:  typeShortInteger
  719.                   Required or Optional?  Required
  720. keyMenuTitle
  721.                   Description:  The title of the menu, as
  722.                                 returned by a Query Menu
  723.                                 List Apple event
  724.                   Descriptor Type:  typeChar
  725.                   Required or Optional?  Optional
  726. NOTE:  Either keyMenuID or keyMenuTitle, or both, must be specified.
  727. keyMenuItemID
  728.                   Description:  The ID of the item, numbered
  729.                                 from 1 at the top of the menu
  730.                   Descriptor Type:  typeShortInteger
  731.                   Required or Optional?  Optional
  732. keyMenuItemText
  733.                   Description:  The text of the item, as
  734.                                 it appears in the menu
  735.                   Descriptor Type:  typeChar
  736.                   Required or Optional?  Optional
  737. NOTE:  Either keyMenuItemID or keyMenuItemText, or both, must be
  738. specified.
  739. keyShiftKeyPressed
  740.                   Description:  Whether the Shift key is
  741.                                 pressed at the time of the
  742.                                 simulated menu selection
  743.                   Descriptor Type:  typeBoolean
  744.                   Required or Optional?  Optional
  745.                   Default Value:  false
  746. keyControlKeyPressed
  747.                   Description:  Whether the Control key is
  748.                                 pressed at the time of the
  749.                                 simulated menu selection
  750.                   Descriptor Type:  typeBoolean
  751.                   Required or Optional?  Optional
  752.                   Default Value:  false
  753. keyOptionKeyPressed
  754.                   Description:  Whether the Option key is
  755.                                 pressed at the time of the
  756.                                 simulated menu selection
  757.                   Descriptor Type:  typeBoolean
  758.                   Required or Optional?  Optional
  759.                   Default Value:  false
  760. keyCommandKeyPressed
  761.                   Description:  Whether the Command key is
  762.                                 pressed at the time of the
  763.                                 simulated menu selection
  764.                   Descriptor Type:  typeBoolean
  765.                   Required or Optional?  Optional
  766.                   Default Value:  false
  767.  
  768. Reply Parameters
  769.  
  770. keyMenuEventsTattoo
  771.                   Description:  A null parameter to verify
  772.                                 that Menu Events handled
  773.                                 the event
  774.                   Descriptor Type:  typeNull
  775.                   Required or Optional?  Required
  776.  
  777. Result Codes
  778.                   mBarNFnd        -126    The application has
  779.                                           no menu bar
  780.                   errAENoUserInteraction
  781.                                   -1713   The application is
  782.                                           refusing to interact
  783.                                           with other processes
  784.                                           or (if Menu Events
  785.                                           extension is locked)
  786.                                           with remote processes
  787.                   noSuchMenuErr   -15950  The application has
  788.                                           no such menu
  789.                   noSuchMenuItemErr
  790.                                   -15951  The menu has no
  791.                                           such item
  792.                   menuItemDisabledErr
  793.                                   -15952  The item is
  794.                                           disabled
  795.                   menuEventPendingErr
  796.                                   -15953  Another Menu event
  797.                                           is already pending
  798.                                           on this application
  799.                   menuMismatchErr
  800.                                   -15955  The given menu ID
  801.                                           and menu title
  802.                                           do not match
  803.                   menuItemMismatchErr
  804.                                   -15956  The given menu item ID
  805.                                           and menu item text
  806.                                           do not match
  807.  
  808.  
  809. Constants defined in the Menu Events suite
  810.  
  811. Constant               Value
  812.  
  813. kAEMEQueryMenu         'qmn '
  814. kAEMEQueryMenuList     'qmn#'
  815. kAEMESelectMenuItem    'semi'
  816. keyCommandKeyPressed   'comk'
  817. keyControlKeyPressed   'conk'
  818. keyMenuEnabled         'mnen'
  819. keyMenuEventsTattoo    'M╛nu'
  820. keyMenuID              'mnid'
  821. keyMenuItemCmd         'micm'
  822. keyMenuItemEnabled     'mien'
  823. keyMenuItemIcon        'miic'
  824. keyMenuItemID          'miid'
  825. keyMenuItemMark        'mima'
  826. keyMenuItemStyle       'mist'
  827. keyMenuItemText        'mite'
  828. keyMenuMDEFID          'mndf'
  829. keyMenuTitle           'mnti'
  830. keyOptionKeyPressed    'optk'
  831. keyShiftKeyPressed     'shik'
  832. kMEEventClass          'M╛nu'
  833. menuEventPendingErr    -15953
  834. menuItemDisabledErr    -15952
  835. menuItemMismatchErr    -15956
  836. menuMismatchErr        -15955
  837. noSuchMenuErr          -15950
  838. noSuchMenuItemErr      -15951
  839.  
  840.  
  841.  
  842. Limitations
  843.  
  844.  
  845. Some applications refuse to submit to the trickery of Menu Events.  The
  846. prime example is any version of Finder which predates the Power
  847. Macintosh (version 7.1.2).  It is not truly an Apple event server, and it
  848. only respects events of known types.  Any other high-level event is not
  849. replied to, and the send will time out.  ResEdit 2.1.1 is similar.  Some
  850. Microsoft applications handle Apple events in a non-standard fashion,
  851. binding their own event handlers over all Apple event classes, and
  852. therefore should not be targeted.
  853.  
  854. The only way to know for sure is to try the ones you are interested in
  855. controlling.  Certainly, anything you write yourself is a candidate, as long
  856. as you follow the practices suggested in Apple documentation, namely:  Be
  857. high-level-event-aware.  Always be ready to accept and dispatch an
  858. Apple event.  Assume that any high-level event you don╒t recognize is an
  859. Apple event, and dispatch it as such.  If an unknown event reaches your
  860. wildcard event handler, return errAEEventNotHandled, so that system
  861. event handlers can get a crack at it.  Don╒t deny other programs on the
  862. same machine the right to request user interaction, which is the default.
  863.  
  864. Another limitation you should know about is that Menu Events can╒t
  865. operate dialogs and alerts which the target application may post in
  866. response to the menu action.  If the menu item text ends in an ellipsis
  867. ('╔') character, you can bet that the application will post a dialog or alert
  868. box.  It is then up to the local user to operate the controls.
  869.  
  870. If the target machine is under the influence of a screen saver or security
  871. package which would present a modal dialog in response to a mouse click,
  872. then Query Menu and Select Menu Item events will time out.  The same is
  873. true if the target machine is already showing a modal dialog, preventing
  874. Menu Events from activating the target application.
  875.  
  876. A known conflict exists between Menu Events and Help on Wheels.  If you
  877. send a Menu event to an application which does a casual help display
  878. before performing the menu action, and if the help server is running,
  879. problems may occur with the application.  The problem is that the Menu
  880. event╒s user interaction ends when the receiving application sends an
  881. Apple event to the help server, causing it to return to the background.  If
  882. the menu action causes a call to the Standard File Manager or any other
  883. code which should not be called when in the background, the application
  884. may hang.
  885.  
  886.  
  887.  
  888. Programmer Notes
  889.  
  890.  
  891. Write to the author at the above address if you want to know more about
  892. the Menu Events extension or how it was programmed.
  893.  
  894.  
  895.  
  896. Acknowledgements
  897.  
  898.  
  899. Thanks to C.K. Haun and the other folks at Apple Developer Technical
  900. Support who put together those clever little code snippets which give
  901. folks like me such odd ideas.
  902.  
  903. Special thanks to the many fine people who beta-tested this software,
  904. including Ken Linger, Chris Reynolds, Michele Marques, Chris Kaltwasser,
  905. James Edward Davis, and Leonard Rosenthol, and to Fred Terry for his
  906. hospitality at the MacScripting mailing list.
  907.  
  908.  
  909.  
  910. Revision History
  911.  
  912.  
  913. 1.3.1 (December 13, 1997)
  914. Ñ  Public AWOL Utilities 1.4 release.
  915. Ñ  Minor changes to trap patches.
  916.  
  917. 1.3 (March 6, 1996)
  918. Ñ  Public AWOL Utilities 1.3 release.
  919. Ñ  Allowed menus and menu items to be specified using string parameters,
  920. with or without the corresponding numeric ID parameters.  An error is
  921. returned if the numeric and string parameters do not match.
  922. Ñ  Added support for modifier keys (Shift, Control, Option, Command) in
  923. the Query Menu event.
  924. Ñ  Improved application compatibility by simulating a menu bar click, to
  925. force the application to update its menus, before reading the contents of a
  926. menu in response to a Query Menu or Select Menu Item event.
  927. Ñ  Changed the response to a menu selection with the Caps Lock key down
  928. to a simple Apple event recording action, instead of having the target
  929. application send itself a Menu event to invite recording.
  930. Ñ  Added an error string parameter to the reply event when an error
  931. occurs.
  932. Ñ  Moved the error codes from the -21000 range to the -15950 range, so
  933. that errors are reported sensibly in AppleScript alerts.
  934. Ñ  Rewrote ╥Menu Events Sample Script╙ to make use of the new optional
  935. string parameters.
  936.  
  937. 1.2 (October 17, 1994)
  938. Ñ  Public AWOL Utilities 1.2 release.
  939. Ñ  No revisions.
  940.  
  941. 1.1.2 (April 19, 1994)
  942. Ñ  Added support for script recording by forcing high-level-event-aware
  943. applications to send themselves Menu events when the user selects a
  944. menu item and the Caps Lock key is down.
  945. Ñ  Added support for modifier keys (Shift, Control, Option, Command) in
  946. the Select Menu Item event.
  947. Ñ  Removed the nonStandardMenuErr (-21004) code in favor of the new
  948. keyMenuMDEFID parameter in the reply to the Query Menu List event, to
  949. improve compatibility with target applications which use slightly
  950. non-standard menu definition procedures.
  951.  
  952. 1.1.1 (April 11, 1994)
  953. Ñ  Added ╥Menu Events Scripting Addition╙ and ╥Menu Events Sample
  954. Script╙ in place of ╥Menu Events 'aete'╙ resource file.
  955.  
  956. 1.1 (March 28, 1994)
  957. Ñ  Public AWOL Utilities 1.1 release.
  958. Ñ  Documented that Menu Events works with Finder 7.1.2.
  959.  
  960. 1.0.7 (March 13, 1994)
  961. Ñ  Menu Events Help presents a useful message if the user tries to open or
  962. print it when the help server is absent.
  963.  
  964. 1.0.6 (February 27, 1994)
  965. Ñ  Added protection against loading duplicate copies of the extension.
  966.  
  967. 1.0.5 (February 6, 1994)
  968. Ñ  Improved compatibility with At Ease and other applications which flush
  969. mouse-down events when they become active.
  970.  
  971. 1.0.4 (January 30, 1994)
  972. Ñ  If the Shift key is pressed on startup, the extension will not be loaded.
  973. If the Help or Command-? key is pressed, the extension will delay up to
  974. one second to let the user release the key(s).
  975.  
  976. 1.0.3 (January 19, 1994)
  977. Ñ  Added ╥Menu Events 'aete'╙ resource file.
  978.  
  979. 1.0.2 (January 11, 1994)
  980. Ñ  Fixed bug which sent the target application into a notification wait state
  981. if it received a Menu event from a remote sender.
  982.  
  983. 1.0.1 (December 31, 1993)
  984. Ñ  Initial AWOL Utilities 1.0.1 release.
  985.